import java.sql.*;

//可滚动的结果集，定位倒数第二条数据
public class Scrollable_Resultset {
    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/mysqlbase";
        String username = "root";
        String password = "1234";
        String sql = "SELECT * FROM teacher WHERE id >?";

        try (Connection conn = DriverManager.getConnection(url, username, password);
            PreparedStatement ps = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY)){
            ps.setInt(1, 10);
            try (ResultSet resultSet = ps.executeQuery()){
                resultSet.absolute(-2);
                System.out.println(resultSet.getObject(1)+" "+resultSet.getString(2) +" "+resultSet.getString(3)+" "+resultSet.getString(4));
            }
        }catch (SQLException e){
            e.printStackTrace();
        }
    }
}
